﻿using BarrageGameAssistant.Core.Configs;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BarrageGameAssistant.UIForms
{
    public partial class FrmMonitorShow : Form
    {
        /// <summary>
        /// 程序配置
        /// </summary>
        public Settings? Settings { get; set; }

        public FrmMonitorShow()
        {
            InitializeComponent();
        }

        private void FrmMonitorShow_Load(object sender, EventArgs e)
        {

        }

        private void FrmMonitorShow_Shown(object sender, EventArgs e)
        {
#pragma warning disable CS8602 // 解引用可能出现空引用。
            Settings.IsMonitorOpen = true;
#pragma warning restore CS8602 // 解引用可能出现空引用。
        }

        private void FrmMonitorShow_FormClosing(object sender, FormClosingEventArgs e)
        {
#pragma warning disable CS8602 // 解引用可能出现空引用。
            Settings.IsMonitorOpen = false;
#pragma warning restore CS8602 // 解引用可能出现空引用。
        }

        public void SetImage(Bitmap? newImage)
        {
            var image = this.pictureBox1.Image;
            Application.DoEvents();
            Invoke((new Action(() =>
            {
                if(newImage != null) 
                {
                    this.Size = newImage.Size;
                    this.Text = $"画面监视器 宽: {newImage?.Size.Width} 高: {newImage?.Size.Height} {this.Width}x{this.Height}";
                }
            })));
            this.pictureBox1.Image = newImage;
            image?.Dispose();
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            
        }
    }
}
